package com.cc.pojo.domain;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 前端路由对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Router {
    /**
     * 菜单ID
     */
    @Schema(description = "菜单ID")
    private Long menuId;
    /**
     * 路由地址
     */
    private String path;
    /**
     * 路由名称（建议唯一）
     */
    private String name;
    /**
     * 组件路径
     */
    private String component;
    /**
     * 重定向地址
     */
    private String redirect;
    /**
     * 父菜单ID
     */
    @Schema(description = "父菜单ID")
    private Long parentId;
    /**
     * 路由元信息
     */
    private Meta meta;
    /**
     * 子路由
     */
    private List<Router> children;

    public Router(Menu menu) {
        this.menuId = menu.getMenuId();
        this.name = menu.getName();
        this.component = menu.getComponent();
        this.redirect = menu.getRedirect();
        this.parentId = menu.getParentId();
        this.path = menu.getPath();
        //判断是否是外链
        if (menu.getIsFrame().equals(0)){
            this.meta = new Router.Meta(
                    new Router.Meta.Title(menu.getTitleZhCn(), menu.getTitleEnUs())
                    , menu.getIcon(), menu.getVisible(), menu.getOrderNum(),menu.getFrameSrc());
        }else {
            this.meta = new Router.Meta(
                    new Router.Meta.Title(menu.getTitleZhCn(), menu.getTitleEnUs())
                    , menu.getIcon(), menu.getVisible(), menu.getOrderNum());
        }

    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Meta {
        /**
         * 标题
         */
        private Title title;
        /**
         * 图标
         */
        private String icon;
        /**
         * 是否隐藏
         */
        private Boolean hidden = false;
        /**
         * 排序
         */
        private Integer orderNo;
        /**
         * 外链地址
         */
        private String frameSrc;

        public Meta(String zh_CN, String en_US, String icon, Boolean hidden, Title title) {
            this.title = new Title(zh_CN, en_US);
            this.icon = icon;
            this.hidden = hidden;
            this.title = title;
        }

        public Meta(String zh_CN, String en_US, String icon, Boolean hidden) {
            this.title = new Title(zh_CN, en_US);
            this.icon = icon;
            this.hidden = hidden;
        }

        public Meta(Title title, String icon, String visible) {
            this.title = title;
            this.icon = icon;
            if ("0".equals(visible)) {
                this.hidden = false;
            } else if ("1".equals(visible)) {
                this.hidden = true;
            }
        }
        public Meta(Title title, String icon, String visible,Integer orderNo,String frameSrc) {
            this.title = title;
            this.icon = icon;
            if ("0".equals(visible)) {
                this.hidden = false;
            } else if ("1".equals(visible)) {
                this.hidden = true;
            }
            this.orderNo=orderNo;
            this.frameSrc=frameSrc;
        }
        public Meta(Title title, String icon, String visible,Integer orderNo) {
            this.title = title;
            this.icon = icon;
            if ("0".equals(visible)) {
                this.hidden = false;
            } else if ("1".equals(visible)) {
                this.hidden = true;
            }
            this.orderNo=orderNo;
        }

        public Meta(String zh_CN, String en_US, String icon) {
            this.title = new Title(zh_CN, en_US);
            this.icon = icon;
        }

        public Meta(Title title, String icon) {
            this.title = title;
            this.icon = icon;
        }
        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        public static class Title {
            /**
             * 中文
             */
            private String zh_CN;
            /**
             * 英文
             */
            private String en_US;
        }
    }
}
